package com.blb.controller;


import com.blb.entity.Hint;
import com.blb.service.IHintService;
import com.blb.utils.DataTablePage;
import com.blb.utils.DataTablesPage;
import com.blb.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *仓库管理的库存预警
 * @author xiaoxiong
 * @since 2020-05-20
 */
@Controller
@RequestMapping("/hint")
public class HintController {

    @Autowired
    private IHintService hintService;
    @RequiresPermissions("storyyu")
    @ResponseBody
    @RequestMapping("/hintAll")
    public DataTablesPage hintAll(Integer draw,String ck,String pname,Integer start, Integer length,String cj,String tj) {
        Map<String,Object> map=new HashMap<>();
        map.put("ck",ck);
        map.put("pname",pname);
        map.put("start",start);
        map.put("length",length);
        if (cj.equals("0") ) {
            map.put("ck", tj);
        } else if (cj.equals("1")) {
            map.put("hq", tj);
        } else if (cj.equals("2")) {
            map.put("hj", tj);
        }

        System.out.println("修改后的Map:" + map);
        int total = hintService.recordsTotal(map);
        List<Map> list = hintService.hintAll(map);
        return new DataTablesPage(draw,total,total,list);

    }

    //设置预警值
    @RequiresPermissions("storyyu:update")
    @ResponseBody
    @RequestMapping("/updateHint")
    public Result updateHint(@RequestParam Map map) {
        System.out.println(map);
        try {
            hintService.updateHint(map);
            return new Result(true,"设置成功");
        }catch (Exception e){
            return new Result(false,"设置失败");
        }

    }

}

